
import * as ActionTypes from './ActionTypes'
export default (state: any, action: any) => {
    const { currentBoxVal, itemsInEditing } = state
    const currentId = currentBoxVal.uid

    switch (action.type) {
        case ActionTypes.SAVEITEMSVAL:
            return { ...state, currentBoxVal: action.values }

        case ActionTypes.INSERTITEMSVAL:
            return { ...state, itemsInEditing: action.values }

        case ActionTypes.RESETITEMSVAL:

            for (let i = 0; i < itemsInEditing.length; i++) {
                if (itemsInEditing[i].uid === currentId) {
                    itemsInEditing[i] = action.values
                }
            }
            const newItem = JSON.parse(JSON.stringify(itemsInEditing))
            return { ...state, itemsInEditing: newItem }

        case ActionTypes.MODIFYITEMSVAL:
            // for (let i = 0; i < itemsInEditing.length; i++) {
            //     if (itemsInEditing[i].uid === currentId) {
            //         itemsInEditing[i].h = action.values.h
            //         itemsInEditing[i].w = action.values.w
            //         itemsInEditing[i].x = action.values.x
            //         itemsInEditing[i].y = action.values.y
            //     }
            // }
            const nItem = JSON.parse(JSON.stringify(itemsInEditing))
            return { ...state, itemsInEditing: nItem }
        default:
            return state
    }
}